'''
Created on Nov 29, 2010

@author: dexen
'''


import time
import random

from dexen import BaseSlaveTask

from my_ind import MyInd
from const import GEN_SIZE
from dexen.system.common.states import MasterState

class EvalATask(BaseSlaveTask):
    def __init__(self):
        pass
    
    def __execute__(self, master_state, inds):
        assert isinstance(master_state, MasterState)
        print "I am in evalA"
        #time.sleep(random.randint(1,6))
        
        if master_state.get_data("ga"):
            print master_state.get_data("ga")
        
        for ind in inds:
            assert isinstance(ind, MyInd)
            cnt = 0
            for gene in ind.phenotype[:GEN_SIZE/2]:
                cnt = cnt + gene
            ind.evalA = cnt
        return inds


class EvalBTask(BaseSlaveTask):
    def __init__(self):
        pass
    
    def __execute__(self, master_state, inds):
        print "I am in evalB"
        #time.sleep(random.randint(1,6))
        for ind in inds:
            assert isinstance(ind, MyInd)
            cnt = 0
            for gene in ind.phenotype[GEN_SIZE/2:]:
                cnt = cnt + gene
            ind.evalB = cnt
        return inds

    